#ifndef _FS_H
#define _FS_H

esp_err_t initFs(void) {
    dispInitInfo("Init SPIFFS...");
    esp_vfs_spiffs_conf_t conf = {
        .base_path = "/www",
        .partition_label = NULL,
        .max_files = 5,
        .format_if_mount_failed = true
    };
    esp_err_t ret = esp_vfs_spiffs_register(&conf);

    if (ret != ESP_OK) {
        if (ret == ESP_FAIL) {
            log("Failed to mount or format filesystem");
        } else if (ret == ESP_ERR_NOT_FOUND) {
            log("Failed to find SPIFFS partition");
        } else {
            log("Failed to initialize SPIFFS (%s)", esp_err_to_name(ret));
        }
        dispInitInfo("SPIFFS init failed.");
        statusClear(STATUS_SPIFFS_OK);
        return ESP_FAIL;
    }

    size_t total = 0, used = 0;
    ret = esp_spiffs_info(NULL, &total, &used);
    if (ret != ESP_OK) {
        log("Failed to get SPIFFS partition information (%s)", esp_err_to_name(ret));
    } else {
        log("Partition size: total: %d, used: %d", total, used);
    }
    dispInitInfo("SPIFFS init done.");
    statusSet(STATUS_SPIFFS_OK);
    return ESP_OK;
}

#endif